home *** CD-ROM | disk | FTP | other *** search
- {$A+,B-,D-,E-,F-,I-,L-,N-,O-,R-,S-,V-}
- {$M 16384,0,655360}
-
- program MakeCase;
-
- {
- Program to generate a case statement of menu choices from a source
- code file created by Turbo Professional's MakeMenu utility.
-
- This code ain't pretty, but it works.
-
- Version 1.00 9 September 1989
- Copyright 1989 by John R. Ackermann, Jr.
-
- Unlimited use may be made of this program under the following conditions:
-
- 1) The user agrees that this program is provided on an "as-is" basis with
- no warranties whatsoever. Under no circumstances will the author be
- liable for any damage allegedly resulting from its use.
-
- 2) If the source code is distributed, this notice may not be removed, and
- any changes from the original must be noted, together with the name of
- the author of the changes.
-
- NOTES:
- 1) This program requires Turbo Professional 5 to compile. But then again,
- if you don't already have TP, you don't need this program!
-
- 2) I developed and tested this program around the code generated by MakeMenu
- in TP Version 5.07. I don't know if code generated by another version
- will work or not. In particular, if leading blanks or zeros are added
- to any of the parameters of the MenuItem procedure, everything will go
- out of whack.
-
- 3) I truncate NameString to 15 characters to allow more room for a long
- function name to the right of the colon. This value can easily be
- by changing the last parameter at line 106 from 15 to another value, and
- by changing the "Copy(Blank,1,15)" statement at line 124 to match the new
- length.
-
- }
-
- uses TPCrt,TPString;
-
- var
- InFile,OutFile : text;
- InString,WorkString : string[255];
- TempString : string[10];
- InFileString,OutFileString : string[60];
- Position : byte;
- TempWord,Code : word;
-
- const
- BlankString : string =
- ' ';
- begin
- ClrScr;
-
- { get input file }
- gotoXY(12,12);
- write('Enter input file name: ');
- ReadLn(InFileString);
- InFileString := CleanPathName(InFileString);
- assign(InFile,InFileString);
- Reset(InFile);
- if (IOResult <> 0) or (Trim(InFileString) = '') then
- begin
- writeln('Unable to open input file: ' + InFileString);
- halt(1);
- end;
-
- { get output file }
- gotoXY(12,14);
- write('Enter output file name: ');
- ReadLn(OutFileString);
- OutFileString := CleanPathName(OutFileString);
- assign(OutFile,OutFileString);
- Rewrite(OutFile);
- if (IOResult <> 0) or (Trim(OutFileString) = '') then
- begin
- writeln('Unable to open output file: ' + OutFileString);
- halt(1);
- end;
-
- { output a header }
- writeln(OutFile,'');
- writeln(OutFile,'{ Case statement generated by MakeCase from ',InFileString,
- ' }');
- writeln(OutFile,'Case Key of ');
-
- { loop through input file }
- while not EOF(InFile) do
- begin
- ReadLn(InFile,InString);
- InString := TrimLead(InString);
- { is it a menu item? }
- if Copy(InString,1,8) = 'MenuItem' then
- begin
- { trim off "MenuItem('" }
- Delete(InString,1,10);
-
- { where's the end of NameString? }
- Position := Pos(#39,InString) - 1;
-
- { turn the first 15 characters of NameString into a comment}
- WorkString := Copy(Copy(InString,1,Position),1,15);
- WorkString := '{' + WorkString + '}';
-
- { get rid of NameString and the trailing "'," }
- Delete(InString,1,Position + 2);
-
- { get rid of DisplayPosP }
- Delete(InString,1,Pos(',',InString));
-
- { get rid of SelectPosP }
- Delete(InString,1,Pos(',',InString));
-
- { get the menu choice, KeyP, convert it to an integer and convert it back
- to TempString formatted to 3 places }
- Val(Copy(InString,1,Pos(',',InString) - 1),TempWord,Code);
- Str(TempWord:3,TempString);
-
- { now add " : ; " to create the case statement }
- WorkString := WorkString + Copy(BlankString,1,(15 - Length(WorkString))) +
- TempString + ' : ;';
-
- { write WorkString to the output file }
- WriteLn(OutFile,WorkString);
- end;
- end;
-
- { write an else statement so that we don't bomb out of an unimplemented
- function }
- writeln(OutFile,'else');
- writeln(OutFile,' begin');
- writeln(OutFile,' gotoXY(17,12);');
- writeln(OutFile,
- ' write(#7,''Sorry... this function isn''''t implemented yet.'');');
- writeln(OutFile,' delay(2000);');
- writeln(OutFile,' end;');
- writeln(OutFile,'end;');
- writeln(OutFile,'');
-
- { close both files }
- Close(InFile);
- Close(OutFile);
- end.